import requests,unittest

class weidu(unittest.TestCase):
    #login 登录
    userId=None
    commodityId = None
    sessionId = None
    def test_weidu_01_login(self):
        url='http://10.59.9.18/small/user/v1/login'
        json={'phone':'15535738398','pwd':'zjj031613'}
        login=requests.post(url=url,json=json)
        print(login.json())
        weidu.userId=str(login.json()['result']['userId'])
        print(weidu.userId)
        self.assertEqual(weidu.userId,'30498')
        self.assertNotEqual(weidu.userId,'6666')
        self.assertTrue(weidu.userId=='30498')
        self.assertFalse(weidu.userId=='3333')
        self.assertIn(weidu.userId,'30498')
        weidu.sessionId = login.json()['result']['sessionId']
        print(weidu.sessionId)

    # commodityList 商品列表
    def test_weidu_02_commodityList(self):
        url = 'http://10.59.9.18/small/commodity/v1/commodityList'
        commodityList = requests.get(url=url)
        print(commodityList.json())
        weidu.commodityId = commodityList.json()['result']['rxxp']['commodityList'][0]['commodityId']
        print(weidu.commodityId)

    # commodityId 商品详情
    def test_weidu_03_commodityId(self):
        url = 'http://10.59.9.18/small/commodity/v1/findCommodityDetailsById'
        params = {
            'commodityId': 7,
            'sessionId': weidu.sessionId
        }
        commodityId = requests.get(url=url, params=params)
        print(commodityId.json())

    #releaseCircle 发布圈子
    def test_weidu_04_releaseCircle(self):
        url='http://10.59.9.18/small/circle/verify/v1/releaseCircle'
        headers={'userId':weidu.userId,'sessionId':weidu.sessionId}
        json={'commodityId':weidu.commodityId,'content':'非常好','image':'List<MultipartBody.Part>'}
        releaseCircle=requests.post(url=url,headers=headers,data=json)
        print(releaseCircle.json())


# 执行
if __name__ == '__main__':
    unittest.main()